/**
 * Created by Administrator on 2015/6/15.
 */
class DisplayController {
    private gameContainer:egret.DisplayObjectContainer;
    private uiLayer:egret.DisplayObjectContainer;
    private effectContainer:egret.DisplayObjectContainer;
    private alertContainer:egret.DisplayObjectContainer;
    public stage:egret.Stage;
    public bg:egret.Bitmap;

    public constructor(){
        //super();
    }

    public setContainer(stage:egret.Stage,gameContainer:egret.DisplayObjectContainer, uiContainer:egret.DisplayObjectContainer){
        this.gameContainer = gameContainer;
        this.uiLayer = uiContainer;
        this.stage = stage;
        var hairContainer = new egret.DisplayObjectContainer();
        this.stage.addChild(hairContainer);
        this.alertContainer = new egret.DisplayObjectContainer();
        this.effectContainer = new egret.DisplayObjectContainer();
        this.stage.addChild(this.effectContainer);
        this.stage.addChild(this.alertContainer);
        PetMgr.getInstance().initContainer(hairContainer);
    }

    public isEffectPlaying(name:string){

    }

    public addtoEffect(child:egret.DisplayObject){
        this.effectContainer.addChild(child);
    }

    public removeFromEffect(child:egret.DisplayObject){
        if( this.effectContainer.contains(child))
            this.effectContainer.removeChild(child);
    }

    public addGameElement(child:egret.DisplayObject){
        if( !this.gameContainer.contains(child) )
            this.gameContainer.addChild(child);
    }

    public removeGameElement(child:egret.DisplayObject){
        this.gameContainer.removeChild(child);
    }

    public addUiElement(child:egret.DisplayObject){
        this.uiLayer.addChild(child);
    }

    public bringElementToTop(child:egret.DisplayObject){
        if( this.uiLayer.getChildIndex(child)!= -1)
            this.uiLayer.setChildIndex(child,this.uiLayer.numChildren-1);
    }

    public removeUiElement(child:egret.DisplayObject){
        if( this.uiLayer.getChildIndex(child) != -1)
            this.uiLayer.removeChild(child);
    }

    public addToAlert(child:egret.DisplayObject){
        if( !this.alertContainer.contains(child)){
            this.alertContainer.addChild(child);
        }
    }
    public removeFromAlert(child:egret.DisplayObject){
        if( this.alertContainer.contains(child)){
            this.alertContainer.removeChild(child);
        }
    }

    private static _instance:DisplayController;
    public static instance():DisplayController{
        if(DisplayController._instance == null)
            DisplayController._instance = new DisplayController();
        return DisplayController._instance;
    }
}